1
|
|
|
/*jslint |
2
|
|
|
indent: 4 |
3
|
|
|
*/ |
4
|
|
|
|
5
|
|
|
/*global |
6
|
|
|
$, google, Lines, Markers, Conversion, Cookies, Coordinates, trackMarker, mytrans, showAlert, |
7
|
|
|
id2alpha, alpha2id, |
8
|
|
|
showProjectionDialog, showLinkDialog, |
9
|
|
|
osmProvider, osmDeProvider, ocmProvider, thunderforestOutdoorsProvider, opentopomapProvider, |
10
|
|
|
get_cookie_int, get_cookie_float, get_cookie_string, |
11
|
|
|
Attribution, Sidebar, ExternalLinks, Hillshading, Geolocation, NPA, CDDA, Freifunk, Okapi, |
12
|
|
|
restoreCoordinatesFormat, |
13
|
|
|
document |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
//var boundariesLayer = null; |
17
|
|
|
//var boundariesLayerShown = false; |
18
|
|
|
var map = null; |
19
|
|
|
var CLAT_DEFAULT = 51.163375; |
20
|
|
|
var CLON_DEFAULT = 10.447683; |
21
|
|
|
var ZOOM_DEFAULT = 12; |
22
|
|
|
var MAPTYPE_DEFAULT = "OSM"; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
function projectFromMarker(id) { |
26
|
|
|
'use strict'; |
27
|
|
|
|
28
|
|
|
trackMarker('project'); |
29
|
|
|
|
30
|
|
|
var mm = Markers.getById(id), |
31
|
|
|
oldpos = mm.getPosition(); |
32
|
|
|
|
33
|
|
|
showProjectionDialog( |
34
|
|
|
function (data1, data2) { |
35
|
|
|
var angle = Conversion.getFloat(data1, 0, 360), |
36
|
|
|
dist = Conversion.getFloat(data2, 0, 100000000000), |
37
|
|
|
newpos, |
38
|
|
|
newmarker; |
39
|
|
|
|
40
|
|
|
if (angle === null) { |
41
|
|
|
showAlert( |
42
|
|
|
mytrans("dialog.error"), |
43
|
|
|
mytrans("dialog.projection.error_bad_bearing").replace(/%1/, data1) |
44
|
|
|
); |
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (dist === null) { |
49
|
|
|
showAlert( |
50
|
|
|
mytrans("dialog.error"), |
51
|
|
|
mytrans("dialog.projection.error_bad_distance").replace(/%1/, data2) |
52
|
|
|
); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
newpos = Coordinates.projection_geodesic(oldpos, angle, dist); |
57
|
|
|
newmarker = Markers.newMarker(newpos, -1, 0, null); |
58
|
|
|
if (newmarker) { |
59
|
|
|
showAlert( |
60
|
|
|
mytrans("dialog.information"), |
61
|
|
|
mytrans("dialog.projection.msg_new_marker").replace(/%1/, newmarker.getAlpha()) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
function storeCenter() { |
70
|
|
|
'use strict'; |
71
|
|
|
|
72
|
|
|
var c = map.getCenter(); |
73
|
|
|
Cookies.set('clat', c.lat(), {expires: 30}); |
74
|
|
|
Cookies.set('clon', c.lng(), {expires: 30}); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
function storeZoom() { |
79
|
|
|
'use strict'; |
80
|
|
|
|
81
|
|
|
Cookies.set('zoom', map.getZoom(), {expires: 30}); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
function storeMapType() { |
86
|
|
|
'use strict'; |
87
|
|
|
|
88
|
|
|
Cookies.set('maptype', map.getMapTypeId(), {expires: 30}); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
function getFeaturesString() { |
93
|
|
|
'use strict'; |
94
|
|
|
|
95
|
|
|
var s = ""; |
96
|
|
|
//if ($('#boundaries').is(':checked')) { s += "b"; } |
97
|
|
|
if ($('#geocaches').is(':checked')) { s += "g"; } |
98
|
|
|
if ($('#hillshading').is(':checked')) { s += "h"; } |
99
|
|
|
if ($('#npa').is(':checked')) { s += "n"; } |
100
|
|
|
if ($('#freifunk').is(':checked')) { s += "f"; } |
101
|
|
|
|
102
|
|
|
return s; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
function getPermalink() { |
107
|
|
|
'use strict'; |
108
|
|
|
|
109
|
|
|
var lat = map.getCenter().lat(), |
110
|
|
|
lng = map.getCenter().lng(); |
111
|
|
|
|
112
|
|
|
return "http://flopp.net/" + |
113
|
|
|
"?c=" + lat.toFixed(6) + ":" + lng.toFixed(6) + |
114
|
|
|
"&z=" + map.getZoom() + |
115
|
|
|
"&t=" + map.getMapTypeId() + |
116
|
|
|
"&f=" + getFeaturesString() + |
117
|
|
|
"&m=" + Markers.toString() + |
118
|
|
|
"&d=" + Lines.getLinesText(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
function generatePermalink() { |
122
|
|
|
'use strict'; |
123
|
|
|
|
124
|
|
|
var link = getPermalink(); |
125
|
|
|
showLinkDialog(link); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
function repairLat(x, d) { |
130
|
|
|
'use strict'; |
131
|
|
|
|
132
|
|
|
if (Coordinates.validLat(x)) { |
133
|
|
|
return x; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return d; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
function repairLon(x, d) { |
141
|
|
|
'use strict'; |
142
|
|
|
|
143
|
|
|
if (Coordinates.validLng(x)) { |
144
|
|
|
return x; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return d; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
function repairRadius(x, d) { |
152
|
|
|
'use strict'; |
153
|
|
|
|
154
|
|
|
if (x === null || isNaN(x) || x < 0 || x > 100000000) { |
155
|
|
|
return d; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return x; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
function repairZoom(x, d) { |
163
|
|
|
'use strict'; |
164
|
|
|
|
165
|
|
|
if (x === null || isNaN(x) || x < 1 || x > 20) { |
166
|
|
|
return d; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return x; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
function repairMaptype(t, d) { |
174
|
|
|
'use strict'; |
175
|
|
|
|
176
|
|
|
var mapTypes = { |
177
|
|
|
"OSM": 1, "OSM/DE": 1, "OCM": 1, "OUTD": 1, "TOPO": 1, "satellite": 1, "hybrid": 1, "roadmap": 1, "terrain": 1 |
178
|
|
|
}; |
179
|
|
|
|
180
|
|
|
if (mapTypes[t]) { |
181
|
|
|
return t; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return d; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
function parseMarkersFromUrl(urlarg) { |
189
|
|
|
'use strict'; |
190
|
|
|
|
191
|
|
|
if (urlarg === null) { |
192
|
|
|
return []; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
var markers = [], |
196
|
|
|
data; |
197
|
|
|
|
198
|
|
|
// ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)? |
199
|
|
|
// COORDS=LAT:LON or DEG or DMMM |
200
|
|
|
if (urlarg.indexOf("*") >= 0) { |
201
|
|
|
data = urlarg.split('*'); |
202
|
|
|
} else { |
203
|
|
|
/* sep is '|' */ |
204
|
|
|
data = urlarg.split('|'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
data.map(function (dataitem) { |
208
|
|
|
dataitem = dataitem.split(':'); |
209
|
|
|
if (dataitem.length < 3 || dataitem.length > 5) { |
210
|
|
|
return; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
var m = { |
214
|
|
|
alpha: dataitem[0], |
215
|
|
|
id: alpha2id(dataitem[0]), |
216
|
|
|
name: null, |
217
|
|
|
coords: null, |
218
|
|
|
r: 0 |
219
|
|
|
}, |
220
|
|
|
index = 1, |
221
|
|
|
lat, |
222
|
|
|
lon; |
223
|
|
|
|
224
|
|
|
if (m.id < 0) { |
225
|
|
|
return; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
lat = parseFloat(dataitem[index]); |
229
|
|
|
lon = parseFloat(dataitem[index + 1]); |
230
|
|
|
if (Coordinates.valid(lat, lon)) { |
231
|
|
|
index += 2; |
232
|
|
|
m.coords = new google.maps.LatLng(lat, lon); |
233
|
|
|
} else { |
234
|
|
|
m.coords = Coordinates.fromString(dataitem[index]); |
235
|
|
|
index += 1; |
236
|
|
|
} |
237
|
|
|
if (!m.coords) { |
238
|
|
|
return; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
m.r = repairRadius(parseFloat(dataitem[index]), 0); |
242
|
|
|
index = index + 1; |
243
|
|
|
|
244
|
|
|
if (index < dataitem.length && |
245
|
|
|
/^([a-zA-Z0-9-_]*)$/.test(dataitem[index])) { |
246
|
|
|
m.name = dataitem[index]; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
markers.push(m); |
250
|
|
|
}); |
251
|
|
|
|
252
|
|
|
return markers; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
function parseCenterFromUrl(urlarg) { |
257
|
|
|
'use strict'; |
258
|
|
|
|
259
|
|
|
if (urlarg === null) { |
260
|
|
|
return null; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
var data = urlarg.split(':'); |
264
|
|
|
|
265
|
|
|
if (data.length === 1) { |
266
|
|
|
return Coordinates.fromString(data[0]); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
if (data.length === 2) { |
270
|
|
|
return Coordinates.toLatLng(parseFloat(data[0]), parseFloat(data[1])); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
return null; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
function parseLinesFromUrl(urlarg) { |
278
|
|
|
'use strict'; |
279
|
|
|
|
280
|
|
|
if (urlarg === null) { |
281
|
|
|
return []; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
var lines = []; |
285
|
|
|
|
286
|
|
|
/* be backwards compatible */ |
287
|
|
|
if (urlarg.length === 3 |
288
|
|
|
&& alpha2id(urlarg[0]) >= 0 |
289
|
|
|
&& urlarg[1] === '*' |
290
|
|
|
&& alpha2id(urlarg[1]) >= 0) { |
291
|
|
|
urlarg = urlarg[0] + ':' + urlarg[2]; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
urlarg.split('*').map(function (pair_string) { |
295
|
|
|
var pair = pair_string.split(':'); |
296
|
|
|
if (pair.length === 2) { |
297
|
|
|
lines.push({source: alpha2id(pair[0]), target: alpha2id(pair[1])}); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
}); |
301
|
|
|
|
302
|
|
|
return lines; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
function parseMarkersFromCookies() { |
307
|
|
|
'use strict'; |
308
|
|
|
|
309
|
|
|
var raw_ids = Cookies.get('markers'), |
310
|
|
|
markers = []; |
311
|
|
|
|
312
|
|
|
if (raw_ids === null || raw_ids === undefined) { |
313
|
|
|
return markers; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
raw_ids.split(':').map(function (id_string) { |
317
|
|
|
var m = {id: null, name: null, coords: null, r: 0}, |
318
|
|
|
raw_data, |
319
|
|
|
data; |
320
|
|
|
|
321
|
|
|
m.id = parseInt(id_string, 10); |
322
|
|
|
if (m.id === null || m.id < 0 || m.id >= 26 * 10) { |
323
|
|
|
return; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
raw_data = Cookies.get('marker' + m.id); |
327
|
|
|
if (!raw_data) { |
328
|
|
|
return; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
data = raw_data.split(':'); |
332
|
|
|
if (data.length !== 4) { |
333
|
|
|
return; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
m.coords = Coordinates.toLatLng(parseFloat(data[0]), parseFloat(data[1])); |
337
|
|
|
if (!m.coords) { |
338
|
|
|
return; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
m.r = repairRadius(parseFloat(data[2]), 0); |
342
|
|
|
|
343
|
|
|
if (/^([a-zA-Z0-9-_]*)$/.test(data[3])) { |
344
|
|
|
m.name = data[3]; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
markers.push(m); |
348
|
|
|
}); |
349
|
|
|
|
350
|
|
|
return markers; |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
function parseLinesFromCookies() { |
355
|
|
|
'use strict'; |
356
|
|
|
|
357
|
|
|
var raw_lines = Cookies.get('lines'), |
358
|
|
|
lines = []; |
359
|
|
|
|
360
|
|
|
if (!raw_lines) { |
361
|
|
|
return lines; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
raw_lines.split('*').map(function (pair_string) { |
365
|
|
|
var pair = pair_string.split(':'); |
366
|
|
|
if (pair.length === 2) { |
367
|
|
|
lines.push({source: alpha2id(pair[0]), target: alpha2id(pair[1])}); |
368
|
|
|
} |
369
|
|
|
}); |
370
|
|
|
|
371
|
|
|
return lines; |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
|
375
|
|
|
function initialize(xcenter, xzoom, xmap, xfeatures, xmarkers, xlines, xgeocache) { |
376
|
|
|
'use strict'; |
377
|
|
|
|
378
|
|
|
var center, |
379
|
|
|
//atDefaultCenter = false, |
380
|
|
|
zoom = parseInt(xzoom, 10), |
381
|
|
|
maptype = xmap, |
382
|
|
|
loadfromcookies = false, |
383
|
|
|
markerdata = parseMarkersFromUrl(xmarkers), |
384
|
|
|
markercenter = null, |
385
|
|
|
clat = 0, |
386
|
|
|
clon = 0; |
387
|
|
|
if (markerdata.length > 0) { |
388
|
|
|
markerdata.map(function (m) { |
389
|
|
|
clat += m.coords.lat(); |
390
|
|
|
clon += m.coords.lng(); |
391
|
|
|
}); |
392
|
|
|
markercenter = new google.maps.LatLng(clat / markerdata.length, clon / markerdata.length); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
if (xcenter && xcenter !== '') { |
396
|
|
|
center = parseCenterFromUrl(xcenter); |
397
|
|
|
} else if (markercenter) { |
398
|
|
|
center = markercenter; |
399
|
|
|
} else { |
400
|
|
|
loadfromcookies = true; |
401
|
|
|
|
402
|
|
|
/* try to read coordinats from cookie */ |
403
|
|
|
clat = get_cookie_float('clat', CLAT_DEFAULT); |
404
|
|
|
clon = get_cookie_float('clon', CLON_DEFAULT); |
405
|
|
|
//if (clat === CLAT_DEFAULT && clon === CLON_DEFAULT) { |
406
|
|
|
// atDefaultCenter = true; |
407
|
|
|
//} |
408
|
|
|
|
409
|
|
|
clat = repairLat(clat, CLAT_DEFAULT); |
410
|
|
|
clon = repairLon(clon, CLON_DEFAULT); |
411
|
|
|
center = new google.maps.LatLng(clat, clon); |
412
|
|
|
|
413
|
|
|
zoom = get_cookie_int('zoom', ZOOM_DEFAULT); |
414
|
|
|
maptype = get_cookie_string('maptype', MAPTYPE_DEFAULT); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
if (!center) { |
418
|
|
|
center = new google.maps.LatLng(CLAT_DEFAULT, CLON_DEFAULT); |
419
|
|
|
//atDefaultCenter = true; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
zoom = repairZoom(zoom, ZOOM_DEFAULT); |
423
|
|
|
maptype = repairMaptype(maptype, MAPTYPE_DEFAULT); |
424
|
|
|
map = new google.maps.Map( |
425
|
|
|
document.getElementById("themap"), |
426
|
|
|
{ |
427
|
|
|
zoom: zoom, |
428
|
|
|
center: center, |
429
|
|
|
scaleControl: true, |
430
|
|
|
streetViewControl: false, |
431
|
|
|
mapTypeControlOptions: { mapTypeIds: ['OSM', 'OSM/DE', 'OCM', 'OUTD', 'TOPO', google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE, google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN] }, |
432
|
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP |
433
|
|
|
} |
434
|
|
|
); |
435
|
|
|
|
436
|
|
|
map.mapTypes.set("OSM", osmProvider("OSM")); |
437
|
|
|
map.mapTypes.set("OSM/DE", osmDeProvider("OSM/DE")); |
438
|
|
|
map.mapTypes.set("OCM", ocmProvider("OCM")); |
439
|
|
|
map.mapTypes.set("OUTD", thunderforestOutdoorsProvider("OUTD")); |
440
|
|
|
map.mapTypes.set("TOPO", opentopomapProvider("TOPO")); |
441
|
|
|
map.setMapTypeId(maptype); |
442
|
|
|
|
443
|
|
|
Attribution.init(map); |
444
|
|
|
Sidebar.init(map); |
445
|
|
|
ExternalLinks.init(map); |
446
|
|
|
Markers.init(map); |
447
|
|
|
Lines.init(map); |
448
|
|
|
Geolocation.init(map); |
449
|
|
|
Hillshading.init(map); |
450
|
|
|
NPA.init(map); |
451
|
|
|
CDDA.init(map); |
452
|
|
|
Freifunk.init(map); |
453
|
|
|
Okapi.init(map); |
454
|
|
|
|
455
|
|
|
//boundariesLayer = new google.maps.ImageMapType({ |
456
|
|
|
// getTileUrl: function(coord, zoom) { |
457
|
|
|
// if (6 <= zoom && zoom <= 16) |
458
|
|
|
// { |
459
|
|
|
// return tileUrl("http://korona.geog.uni-heidelberg.de/tiles/adminb/?x=%x&y=%y&z=%z", ["dummy"], coord, zoom); |
460
|
|
|
// } |
461
|
|
|
// else |
462
|
|
|
// { |
463
|
|
|
// return null; |
464
|
|
|
// } |
465
|
|
|
// }, |
466
|
|
|
// tileSize: new google.maps.Size(256, 256), |
467
|
|
|
// name: "adminb", |
468
|
|
|
// alt: "Administrative Boundaries", |
469
|
|
|
// maxZoom: 16 }); |
470
|
|
|
|
471
|
|
|
map.setCenter(center, zoom); |
472
|
|
|
|
473
|
|
|
google.maps.event.addListener(map, "center_changed", function () { |
474
|
|
|
storeZoom(); |
475
|
|
|
storeCenter(); |
476
|
|
|
}); |
477
|
|
|
google.maps.event.addListener(map, "zoom_changed", function () { |
478
|
|
|
storeZoom(); |
479
|
|
|
storeCenter(); |
480
|
|
|
}); |
481
|
|
|
google.maps.event.addListener(map, "maptypeid_changed", function () { |
482
|
|
|
storeMapType(); |
483
|
|
|
}); |
484
|
|
|
|
485
|
|
|
if (loadfromcookies) { |
486
|
|
|
parseMarkersFromCookies().map(function (m) { |
487
|
|
|
Markers.newMarker(m.coords, m.id, m.r, m.name); |
488
|
|
|
}); |
489
|
|
|
|
490
|
|
|
parseLinesFromCookies().map(function (m) { |
491
|
|
|
Lines.newLine(m.source, m.target); |
492
|
|
|
}); |
493
|
|
|
} else { |
494
|
|
|
markerdata.map(function (m) { |
495
|
|
|
Markers.newMarker(m.coords, m.id, m.r, m.name); |
496
|
|
|
}); |
497
|
|
|
|
498
|
|
|
parseLinesFromUrl(xlines).map(function (m) { |
499
|
|
|
Lines.newLine(m.source, m.target); |
500
|
|
|
}); |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
Okapi.setShowCache(xgeocache); |
504
|
|
|
Sidebar.restore(true); |
505
|
|
|
xfeatures = xfeatures.toLowerCase(); |
506
|
|
|
if (xfeatures === '[default]') { |
507
|
|
|
Hillshading.restore(false); |
508
|
|
|
//restoreBoundaries(false); |
509
|
|
|
Okapi.restore(false); |
510
|
|
|
NPA.toggle(false); |
511
|
|
|
CDDA.toggle(false); |
512
|
|
|
Freifunk.toggle(false); |
513
|
|
|
} else { |
514
|
|
|
Hillshading.toggle(xfeatures.indexOf('h') >= 0); |
515
|
|
|
//toggleBoundaries(xfeatures.indexOf('b') >= 0); |
516
|
|
|
Okapi.toggle(xfeatures.indexOf('g') >= 0); |
517
|
|
|
NPA.toggle(xfeatures.indexOf('n') >= 0); |
518
|
|
|
Freifunk.toggle(xfeatures.indexOf('f') >= 0); |
519
|
|
|
} |
520
|
|
|
restoreCoordinatesFormat("DM"); |
521
|
|
|
|
522
|
|
|
if (xgeocache !== "") { |
523
|
|
|
Okapi.toggle(true); |
524
|
|
|
//atDefaultCenter = false; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
Attribution.forceUpdate(); |
528
|
|
|
|
529
|
|
|
//if (atDefaultCenter) { |
530
|
|
|
// Geolocation.whereAmI(); |
531
|
|
|
//} |
532
|
|
|
} |
533
|
|
|
|